﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;

    public class ImageLoader {

        private var m_url:String = null;
        private var m_content:DisplayObject;
        private var m_callbacks:Array;
        private var m_isLoading:Boolean;
        private var m_loader:Loader;

        public function ImageLoader(_arg1:String){
            this.m_url = _arg1;
            this.m_callbacks = new Array();
        }
        public function getContent(_arg1:Function):void{
            if (this.m_content){
                this.clone(this.m_content, _arg1);
            } else {
                this.m_callbacks.push(_arg1);
                if (!this.m_isLoading){
                    this.m_loader = LoadingManager.load(this.m_url, this.onLoad);
                    this.m_isLoading = true;
                };
            };
        }
        public function onLoad(_arg1:Event):void{
            var _local2:int;
            this.m_loader = (_arg1.target.loader as Loader);
            this.m_loader.removeEventListener(Event.COMPLETE, this.onLoad);
            if (this.m_loader.content){
                this.m_content = this.m_loader.content;
            };
            if (this.m_content){
                _local2 = 0;
                while (_local2 < this.m_callbacks.length) {
                    this.clone(this.m_content, (this.m_callbacks[_local2] as Function));
                    _local2++;
                };
            };
        }
        public function clone(_arg1:DisplayObject, _arg2:Function):void{
            var _local3:LoaderWithInfo;
            if ((_arg1 is MovieClip)){
                _local3 = new LoaderWithInfo();
                _local3.info.callbackFunction = (_arg2 as Function);
                _local3.contentLoaderInfo.addEventListener(Event.COMPLETE, this.onClone);
                _local3.loadBytes(this.m_content.loaderInfo.bytes);
            } else {
                if ((_arg1 is Bitmap)){
                    _arg2(new Bitmap((this.m_content as Bitmap).bitmapData));
                };
            };
        }
        public function onClone(_arg1:Event):void{
            var _local2:LoaderWithInfo = (_arg1.target.loader as LoaderWithInfo);
            _local2.info.callbackFunction(_arg1.target.loader.content);
        }

    }
}//package Classes 
